package com.xinqi.modules.sys.dict.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.dict.client.DictDocumentClient;
import com.xinqi.modules.sys.dict.dto.req.DictDocumentCreateDTO;
import com.xinqi.modules.sys.dict.dto.req.DictDocumentQueryDTO;
import com.xinqi.modules.sys.dict.dto.req.DictDocumentUpdateDTO;
import com.xinqi.modules.sys.dict.dto.rsp.DictDocumentResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 文档分类字典表降级处理
 *
 * @author: gzy
 * @date: 2023/05/28
 */
@Slf4j
@Component
public class DictDocumentFallbackFactory implements FallbackFactory<DictDocumentClient> {

    @Override
    public DictDocumentClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new DictDocumentClient() {
            @Override
            public R<PageInfo<DictDocumentResultDTO>> page(DictDocumentQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<DictDocumentResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Long> insert(DictDocumentCreateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> update(Long id, DictDocumentUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> delete(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
